from retrieve.base_retrieve import BaseRetrieve


class TextRetrieve(BaseRetrieve):
    def get_query_template(self):
        query_templates = {
            "query": {
                "match": {
                    "description": {
                        "query": ""
                    }
                }
            },
            "size": 50
        }
        return query_templates

    def complete_query(self, global_resource, request_content, response_content):
        body = self.get_query_template()
        word_info = request_content.get_value("word_info")
        final_query = " ".join([" ".join([key]+word_info[key]["sim_words"])if word_info[key]["idf"] > 1 else "" for key in word_info])
        body["query"]["match"]["description"]["query"] = final_query
        return body
